<template>
  <div class="main-index">
    <div class="main-top-center">
      <router-link :to="{ path:url }">
        <div class="index-head">
          <div class="index-img"  ><img :src="schoolInfo.image" alt="" /></div>
          <!--   <div class="index-item">慧教云</div><div class="index-img" v-else><img :src="user.avatar" alt="" /></div> -->
        </div>
      </router-link>
      <div class="user-info">
        <div>
          <el-badge is-dot class="item notice-num"  v-if="status != 0 "> <router-link :to="{ path: 'msglist' }">
            <img style="cursor: pointer;  float: left;" src="../../static/img/ico-notice.png" alt="" />
          </router-link></el-badge>
        <router-link :to="{ path: 'msglist' }"  class=" item notice-num"   v-if="status == 0 ">
            <img style="cursor: pointer;  float: left;" src="../../static/img/ico-notice.png" alt="" />
          </router-link>

          欢迎您，{{ userInfo.nickname }}
        </div>
        <div class="user-img">
          <el-dropdown>
            <div class="block" v-if="userInfo.avatar==''"><el-avatar :src="circleUrl"></el-avatar></div>
            <div class="block" v-else><el-avatar :src="userInfo.avatar"></el-avatar></div>
            <el-dropdown-menu slot="dropdown">
<!--
              <router-link :to="{ path: 'msglist' }">
                <el-dropdown-item>
                  <i class="el-icon-bell"></i>
                  消息中心
                </el-dropdown-item>
              </router-link>
-->
              <router-link :to="{ path: 'setting' }">
                <el-dropdown-item>
                  <i class="el-icon-s-tools"></i>
                  我的设置
                </el-dropdown-item>
              </router-link>
              <router-link :to="{ path: 'feedback' }">
                <el-dropdown-item>
                  <i class="el-icon-s-order"></i>
                  建议反馈
                </el-dropdown-item>
              </router-link>
              <router-link :to="{ path: 'index' }"  v-if="isindex == true ">
                <el-dropdown-item>
                  <i class="el-icon-s-home"></i>
                  平台主页
                </el-dropdown-item>
              </router-link>
              <a  @click="logOut()"><el-dropdown-item>
                <i class="el-icon-error"></i>
                退出登录
              </el-dropdown-item>
              </a>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>

      <div class="close-img" style="display: none;" @click="logOut()"><img src="../../static/img/close.png" alt="" /></div>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapMutations } from 'vuex';
export default {
  props: {
    user: {
      type: Object,
      default: function() {
        return {};
      }
    },
    isShowMyCourse:false,

  },
  data() {
    return {
      circleUrl: 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png',
      status: 0,
      isindex: false,
      schoolInfo: JSON.parse(localStorage.getItem('schoolInfo' )),
      userInfo:JSON.parse(localStorage.getItem('userInfo' )),
       url:localStorage.getItem('jump_path')
    };
  },
  created() {
   this.isindex = this.$route.path.indexOf("/index") != -1 ;
    this.getInfo();
    this.getLogo();
    this.getmessageStatus();
    this.checkAuth();
  },
  methods: {
    checkAuth(){
      let userAuth = JSON.parse(localStorage.getItem('userAuth'));
      let jump_url =   userAuth.jump_path;
      if(jump_url == '/index' ){
        this.isindex = true;
      }
    },
    getLogo() {
        this.$api('index.getLogo', {}).then(res => {
          this.schoolInfo = res.data;
          localStorage.setItem('schoolInfo', JSON.stringify(res.data));
        });
    },
    logOut() {
      localStorage.setItem('schoolInfo', "");
      localStorage.setItem('token', "");
      this.$router.push('/');
    },
    getmessageStatus() {
      this.$api('message.getmessageStatus', { token: localStorage.getItem('token') }).then(res => {
      this.status = res.data.status;
      });
    },
    getInfo() {
      this.userInfo = JSON.parse(localStorage.getItem('userInfo' ));
    }
  }
};
</script>

<style lang="scss" scoped></style>
